package com.wantup.miaosha.config;

import com.github.tobato.fastdfs.FdfsClientConfig;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableMBeanExport;
import org.springframework.context.annotation.Import;
import org.springframework.jmx.support.RegistrationPolicy;
import org.springframework.util.unit.DataSize;
import org.springframework.util.unit.DataUnit;

import javax.servlet.MultipartConfigElement;

/**
 * 导入FastDFS-Client组件
 * 
 * @author Created by zhaoluowei on 2018/12/14.
 *
 */
@Configuration
@Import(FdfsClientConfig.class)
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)// 解决jmx重复注册bean的问题
public class FastdfsImporter {
    // 导入依赖组件


    @Bean
    public MultipartConfigElement multipartConfigElement(){
        MultipartConfigFactory configFactory = new MultipartConfigFactory();
        //设置文件最大上传大小
        DataSize dataSize = DataSize.of(100, DataUnit.MEGABYTES);
        configFactory.setMaxFileSize(dataSize);

        //设置总上传数据大小
        configFactory.setMaxRequestSize(DataSize.of(100,DataUnit.MEGABYTES));

        return configFactory.createMultipartConfig();
    }


}